﻿using System;

class Program
{
    static int score = 0;
    static void Main()
    {
        bool playAgain = true;
        while (playAgain)
        {
            Random random = new Random();
            int targetNumber = random.Next(1, 101);
            int attempts = 0;
            bool guessedCorrectly = false;
            Console.WriteLine("欢迎来到猜数字游戏！");
            Console.WriteLine($"我已经想好了一个1到100之间的数字，快来猜一猜吧。当前积分: {score}");

            while (!guessedCorrectly)
            {
                Console.Write("请输入你的猜测: ");
                if (int.TryParse(Console.ReadLine(), out int guess))
                {
                    attempts++;
                    if (guess < targetNumber)
                    {
                        Console.WriteLine("小了，请再试一次。");
                    }
                    else if (guess > targetNumber)
                    {
                        Console.WriteLine("大了，请再试一次。");
                    }
                    else
                    {
                        guessedCorrectly = true;
                        if (attempts <= 3)
                        {
                            score += 3;
                        }
                        else
                        {
                            score += 1; 
                        }
                        Console.WriteLine($"恭喜你，猜对了！你用了 {attempts} 次猜出了数字。当前积分: {score}");
                    }
                }
                else
                {
                    Console.WriteLine("输入无效，请输入一个整数。");
                }
            }

            Console.Write("是否继续游戏？(y/n): ");
            string response = Console.ReadLine().ToLower();
            playAgain = response == "y";
        }

        Console.WriteLine($"游戏结束，你的最终积分是: {score}");
    }
}